<%--
    Document   : index
    Created on : Nov 14, 2011, 12:01:13 AM
    Author     : Ismail Sunni
--%>

<%@page import="java.util.ArrayList" %>
<%@page import="models.Kategori" %>
<% ArrayList<Kategori> objKategori = (ArrayList<Kategori>) request.getAttribute("listKategori");%>
<% String[] listStatusPesanan = (String[]) request.getAttribute("listStatusPesanan");%>
<% int[] listIDStatusPesanan = (int[]) request.getAttribute("listIDStatusPesanan");%>

<h1>Generate Laporan</h1>
<form id="addBarangForm" action="<%=request.getContextPath()%>/laporan" method="POST">
    <table>
        <tr>
            <td>
                <label>Dari</label>
            </td>
            <td>
                <input  type="text" name="start_date" id="start_date"
                        class="datepicker" value="<%= (request.getAttribute("startdate") != null ? request.getAttribute("startdate") : "Pilih Tanggal")%>">
            </td>
        </tr>
        <tr>
            <td>
                <label>Sampai</label>
            </td>
            <td>
                <input  type="text" name="end_date" id="end_date"
                        class="datepicker" value="<%= (request.getAttribute("enddate") != null ? request.getAttribute("enddate") : "Pilih Tanggal")%>">
            </td>
        </tr>
        <tr>
            <td><label>Kategori</label></td>
            <td>
                <select name="kategoriBarang">
                    <%
                                int chosen_categ = 0;
                                if (request.getAttribute("chosen_categ") != null) {
                                    chosen_categ = (Integer) request.getAttribute("chosen_categ");
                                }
                                if (chosen_categ == 0) {
                    %>
                    <option value="0" selected="true">Semua</option>
                    <%                                } else {
                    %>
                    <option value="0">Semua</option>
                    <%                                }
                                for (int i = 0; i < objKategori.size(); i++) {
                                    if (chosen_categ == objKategori.get(i).id) {
                    %>
                    <option value="<%= objKategori.get(i).id%>" selected="true" ><%= objKategori.get(i).nama%></option>
                    <%
                                                        } else {
                    %>
                    <option value="<%= objKategori.get(i).id%>"  ><%= objKategori.get(i).nama%></option>
                    <%
                                    }
                                }
                    %>
                </select>
            </td>
        </tr>
        <tr>
            <td><label>Status</label></td>
            <td>
                <select name="statusPesanan">
                    <%
                                int chosen_status = 0;
                                if (request.getAttribute("chosen_status") != null) {
                                    chosen_status = (Integer) request.getAttribute("chosen_status");
                                }
                                for (int i = 0; i < listStatusPesanan.length; i++) {
                                    if (chosen_status == listIDStatusPesanan[i]) {
                    %>
                    <option value="<%= listIDStatusPesanan[i]%>" selected="true"><%= listStatusPesanan[i]%></option>
                    <%                                                        } else {
                    %>
                    <option value="<%= listIDStatusPesanan[i]%>"><%= listStatusPesanan[i]%></option>
                    <%
                                    }
                                }
                    %>
                </select>
            </td>
        </tr>
        <tr><td></td><td><input type="submit" value="Bangkitkan Laporan" /></td></tr>
                <%
                            if (request.getAttribute("pathLaporan") != null) {
                %>
        <tr><td></td><td><a href="<%=request.getContextPath() + "/upload/Laporan Penjualan Barang.xls"%>">Laporan</a></td></tr>
        <tr><td></td><td><h6>klik kanan, save as untuk menyimpan</h6></td></tr>
        <%}%>
    </table>
</form>


<script type="text/javascript">
    $(function() {
        $( ".datepicker" ).datepicker({ dateFormat: 'yy-mm-dd' });

    });
</script>